package net.sourceforge.peers.gui;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.sourceforge.peers.Logger;
import net.sourceforge.peers.sip.transport.SipResponse;

public class CallFrameStateRinging extends CallFrameState {

    public CallFrameStateRinging(String id, CallFrame callFrame, Logger logger) {
        super(id, callFrame, logger);
        callPanel = new JPanel();
        callPanel.add(new JLabel("正在振铃..."));
        JButton hangupButton = new JButton("挂断");
        hangupButton.setActionCommand(CallFrame.HANGUP_ACTION_COMMAND);
        hangupButton.addActionListener(callFrame);
        callPanel.add(hangupButton);
    }

    @Override
    public void hangupClicked() {
        callFrame.setState(callFrame.TERMINATED);
        callFrame.hangup();
        callFrame.close();
    }

    @Override
    public void calleePickup() {
        callFrame.setState(callFrame.SUCCESS);
        callFrame.setCallPanel(callFrame.SUCCESS.callPanel);
    }

    @Override
    public void error(SipResponse sipResponse) {
        callFrame.setState(callFrame.FAILED);
        callFrame.setCallPanel(callFrame.FAILED.callPanel);
        callFrame.addPageEndLabel("失败原因: "
                + sipResponse.getReasonPhrase());
    }

}
